﻿using MediatR;
using Production_Get.API.Infrastructures.Interfaces;
using Return.Enum;
using THE_WIND_RISES.Common.Domans.BasicInformation.Materials;
using THE_WIND_RISES.Common.Domans.Produce.Craft;
using THE_WIND_RISES.Common.Domans.Produce.Resources;
using THE_WIND_RISES.Common.Dtos;

namespace Production_Get.API.Application.Commands.Technologys
{
    public class ItemInfoShowHandler : IRequestHandler<ItemInfoShowCommand, THE_WIND_RISES.Common.Dtos.Result>
    {
        private readonly IBaseRepositoryGet<ItemInfo> ItemInforepository;
        /// <summary>
        /// 日志
        /// </summary>
        private readonly ILogger<ItemInfoShowHandler> logger;
        public ItemInfoShowHandler(IBaseRepositoryGet<ItemInfo> ItemInforepository, ILogger<ItemInfoShowHandler> logger)
        {
            this.ItemInforepository = ItemInforepository;
            this.logger = logger;

        }
        public async Task<Result> Handle(ItemInfoShowCommand request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCodes.Search };

           
            try
            {
                logger.LogInformation("查询物料信息");
                string sql = "SELECT * FROM ItemInfo";
                var list = ItemInforepository.GetAll(sql, default).ToList();
                if (list != null)
                {
                    result.Code = (int)CommonErrorCodes.Success;
                    result.Data = list;
                    result.Msg = "显示成功";
                }

                return result;
            }
            catch (Exception ex)
            {
                logger.LogError("查询物料信息失败", ex.Message);
                throw;
            }
        }
    }
}
